﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Controls;


namespace TournamentDatabase.Rules
{
	class StringLengthValidationRule : ValidationRule
	{
		double minLength;
		double maxLength;

		public double MinLength
		{
			get { return this.minLength; }
			set { this.minLength = value; }
		}

		public double MaxLength
		{
			get { return this.maxLength; }
			set { this.maxLength = value; }
		}

		public override ValidationResult Validate(object value, CultureInfo cultureInfo)
		{
			string name = (string)value;
			//return new ValidationResult(true, "Test pass.");

			// Is in range?
			if ((name.Length < this.minLength) || (name.Length > this.maxLength))
			{
				string msg = string.Format("Name must be between {0} and {1} characters long. " + name, this.minLength, this.maxLength);
				return new ValidationResult(false, msg);
			}

			// Number is valid
			return new ValidationResult(true, null);
		}

	}
}
